/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.Date;
import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchdienbienhochamException;
import doan.quanlycanbo.portlet.NoSuchdienbienluongException;
import doan.quanlycanbo.portlet.model.dienbienluong;
import doan.quanlycanbo.portlet.service.base.dienbienluongLocalServiceBaseImpl;

/**
 * The implementation of the dienbienluong local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link doan.quanlycanbo.portlet.service.dienbienluongLocalService} interface.
 * </p>
 *
 * <p>
 * Never reference this interface directly. Always use {@link doan.quanlycanbo.portlet.service.dienbienluongLocalServiceUtil} to access the dienbienluong local service.
 * </p>
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Nguyen Tuan Vinh
 * @see doan.quanlycanbo.portlet.service.base.dienbienluongLocalServiceBaseImpl
 * @see doan.quanlycanbo.portlet.service.dienbienluongLocalServiceUtil
 */
public class dienbienluongLocalServiceImpl
	extends dienbienluongLocalServiceBaseImpl {
	
		public dienbienluong getByPrimaryKey(long madbl) throws NoSuchdienbienluongException, SystemException{
			return dienbienluongPersistence.findByPrimaryKey(madbl);
		}
		
		public List<dienbienluong> getAll() throws SystemException{
			return dienbienluongPersistence.findAll();
		}
	
		public List<dienbienluong> getByHoso(long mahoso) throws SystemException{
			return dienbienluongPersistence.findByHoSo(mahoso);
		}
		
		public dienbienluong addDBL(dienbienluong dbl1, long userId) throws SystemException{
			long madbl = CounterLocalServiceUtil.increment(dienbienluong.class.getName());
			
			dienbienluong dbl2 = dienbienluongPersistence.create(madbl);		
			dbl2.setGroupId(dbl1.getGroupId());
			dbl2.setCompanyId(dbl1.getCompanyId());
			dbl2.setLanguageId(dbl1.getLanguageId());
			dbl2.setMahoso(dbl1.getMahoso());
			dbl2.setMahesoluong(dbl1.getMahesoluong());
			dbl2.setTungay(dbl1.getTungay());
			dbl2.setDenngay(dbl1.getDenngay());
			try {
				resourceLocalService.addResources(dbl1.getCompanyId(), dbl1.getGroupId(), userId, 
						dienbienluong.class.getName(), dbl2.getPrimaryKey(), false, true, true);
			} catch (PortalException e) {
				e.printStackTrace();
			}
			
			return dienbienluongPersistence.update(dbl2, false);
		}
		
		public dienbienluong updateDBL(long madbl,long mahesoluong, Date tungay, Date denngay) throws NoSuchdienbienhochamException, SystemException, NoSuchdienbienluongException{
			dienbienluong dbl = dienbienluongPersistence.findByPrimaryKey(madbl);
			dbl.setMahesoluong(mahesoluong);
			dbl.setTungay(tungay);
			dbl.setDenngay(denngay);
			return dienbienluongPersistence.update(dbl, false);
		}
		
		public void deleteDBL(long madbl) throws SystemException, PortalException{
			dienbienluong dbl = dienbienluongPersistence.findByPrimaryKey(madbl);
			deleteDBL(dbl);
		}
		
		public void deleteDBL(dienbienluong dbl) throws PortalException, SystemException{
			resourceLocalService.deleteResource(dbl.getCompanyId(), dienbienluong.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, dbl.getPrimaryKey());
			dienbienluongPersistence.remove(dbl);
		}
}